package com.asiainfo.ai.admin.utils;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;

public class AESUtil {

    /**
     * aes加密
     *
     * @param clientSecret 原始密钥
     */
    public static String encryptAesEncrypt(String clientId, String clientSecret) {
        //构建--用clientId作为密钥
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, "bc39e70327ac4b1186a9a69ead73474e".getBytes());
        //加密为16进制表示
        String encryptHex = aes.encryptHex(clientSecret);
        return encryptHex;
    }

    /**
     * aes解密
     *
     * @param encryptClientSecret clientApp表里边的aes加密后密码
     */
    public static String decryptAesEncrypt(String clientId, String encryptClientSecret) {
        //构建--用clientId作为密钥
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, "bc39e70327ac4b1186a9a69ead73474e".getBytes());
        //加密为16进制表示
        String decryptStr = aes.decryptStr(encryptClientSecret, CharsetUtil.CHARSET_UTF_8);
        return decryptStr;
    }
}
